package com.termine.jsf;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.termine.bean.Bean;
import com.termine.entity.Location;
import com.termine.entity.ServiceSelectItem;
import com.termine.util.Logger;

@ManagedBean
@SessionScoped
public class AppointmentJSF extends Bean implements Serializable {

	private static final long serialVersionUID = -2895978536940711419L;
	
    private List<ServiceSelectItem> services;     
    private List<ServiceSelectItem> filteredServices;  
	private ServiceSelectItem selectedService;
	private Location location;
	private Date start;
	
	/*
	 * Init
	 */
	@PostConstruct
	public void init() {
		try {
			services = getServiceDAO().getAllServices();
			location = new Location();
			start = new Date();
			selectedService = null;
		} catch (Exception e) {
			Logger.log(e.getMessage());
			e.printStackTrace();
		}
	}
	
	/*
	 * Jsf Action Methods
	 */
	public String addAppointment() {
		if (getAppointmentManager().addAppointment(location, selectedService, start)) {
			init();
			getClientScheduleJSF().init();
			return "SUCCESS";
		}
		return "ERROR";
	}
	
	/*
	 * Getters & Setters
	 */
	public ServiceSelectItem getSelectedService() {
		return selectedService;
	}

	public void setSelectedService(ServiceSelectItem selectedService) {
		this.selectedService = selectedService;
	}

	public Location getLocation() {
		return location;
	}

	public void setLocation(Location location) {
		this.location = location;
	}

	public List<ServiceSelectItem> getServices() {
		return services;
	}

	public void setServices(List<ServiceSelectItem> services) {
		this.services = services;
	}

	public List<ServiceSelectItem> getFilteredServices() {
		return filteredServices;
	}

	public void setFilteredServices(List<ServiceSelectItem> filteredServices) {
		this.filteredServices = filteredServices;
	}

	public Date getStart() {
		return start;
	}

	public void setStart(Date start) {
		this.start = start;
	}
	
}